<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>比赛报名注册界面</title>
  <meta name="description" content="particles.js is a lightweight JavaScript library for creating particles.">
  <meta name="author" content="Vincent Garreau" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<script src="js/particles.min.js"></script>
  <link rel="stylesheet" media="screen" href="css/style.css">
  <link rel="stylesheet" type="text/css" href="css/reset.css"/>
	<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div id="particles-js">
		<div class="login " style="height: 550px">
			<div class="login-top">
				注册账号
			</div>
			<div class="login-center clearfix">
				<div class="login-center-img"><img src="img/name.png"/></div>
				<div class="login-center-input">
					<input @blur="blurEmail" type="text" class="email" name="" value="" placeholder="邮箱" onfocus="this.placeholder=''" onblur="this.placeholder='邮箱'"/>
					<div class="login-center-input-text">邮箱</div>
				</div>
			</div>
			<div class="login-center clearfix">
				<div class="login-center-img"><img src="img/password.png"/></div>
				<div class="login-center-input">
					<input @blur="blurPass" type="password" class="password" name="" value="" placeholder="密码" onfocus="this.placeholder=''" onblur="this.placeholder='密码'"/>
					<div class="login-center-input-text">密码</div>
				</div>
			</div>
			<div class="login-center clearfix">
				<div class="login-center-img"><img src="img/password.png"/></div>
				<div class="login-center-input">
					<input @blur="repeatVerification" type="password" name="" value="" class="confirmPass" placeholder="确认密码"/>
					<div class="login-center-input-text">确认密码</div>
				</div>
			</div>
			<div class="login-center clearfix" style="margin-bottom: 10px">
				<div class="login-center-img"><img src="img/password.png"/></div>
				<div class="login-center-input" style="width: 115px;float: left;">
					<input type="text" class="verification-code" name="" value="" placeholder="验证码" onfocus="this.placeholder=''" onblur="this.placeholder='验证码'"/>
					<div class="login-center-input-text">验证码</div>
				</div>
<!--				<button class="button-code" style=" line-height:  float: right;height: 30px;background-color: #1e90ff;border: none;color: white;cursor:pointer">发送验证码</button>-->
				<el-button  :disabled="isBut" style="font-size:13px;padding: 8px 8px;float: right"  :plain="true" @click="open1" >{{content}}</el-button>
			</div>
			<div class="login-button  " @click="registered" v-loading="loading">
				注册
			</div>
			<div class="login-button">
				<a href="log.html" style="color: aliceblue;">去登录</a>
			</div>
		</div>
		<div class="sk-rotating-plane"></div>
</div>

<!-- scripts -->


<script src="js/app.js"></script>
<script src="js/jquery.js"></script>
<!-- import Vue before Element -->
<script src="js/vue.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>

<script >
	new Vue({
		el: '#particles-js',
		data: {
			content: '发送验证码', // 按钮里显示的内容
			totalTime: 120 ,     //记录具体倒计时时间
			timer: 'cloak',  // 定时器名称
			canClick: true, //添加canClick  判断按钮能否点击
			isBut:false,
			loading: false
		},
		methods: {
			open1() {
				var that=this;
				var email=$(".email").val();
				var emailPatt = /^[a-z\d]+(\.[a-z\d]+)*@([\da-z](-[\da-z])?)+(\.{1,2}[a-z]+)+$/;
				if (!emailPatt.test(email)){
					Vue.prototype.$message({
						message:'账户不合法',
						type: 'error'
					});
					return false;
				}else {
					if (!this.canClick) return  //改动的是这两行代码,限制点击
					this.canClick = false
					this.isBut=true
					that.content = this.totalTime + 's后重新发送';
					that.cloak = setInterval(function () {
						that.totalTime--
						if (that.totalTime > 0){
							that.content = that.totalTime + 's后重新发送'
						}
						if (that.totalTime <= 0) {
							window.clearInterval(that.cloak)
							that.content = '重新发送验证码';
							that.totalTime = 120;
							that.canClick = true
							that.isBut=false
						}
						},1000)
					$.post(
									"/competitions/mall.do",
									{mailbox:email},
									function (data) {
										var  Content=data.responseContent;
										if (data.responseCode===200){
											Vue.prototype.$message({
												message:Content,
												type: 'success'
											});
										}else {
											Vue.prototype.$message.error(Content);
										}
									},"json"
					)
				}

			},
			blurEmail() {
				var emailText = $(".email").val();
				var emailPatt = /^[a-z\d]+(\.[a-z\d]+)*@([\da-z](-[\da-z])?)+(\.{1,2}[a-z]+)+$/;
				if (!emailPatt.test(emailText)){
					Vue.prototype.$message({
						message:'账户不合法',
						type: 'warning'
					});
				}
			},
			blurPass(){
				var passwordPatt = /^\w{5,12}$/;
				var pass=$(".password").val();
				if (!passwordPatt.test(pass)){
					Vue.prototype.$message({
						message:'密码安全性低！',
						type: 'warning'
					});
				}
			},
			repeatVerification(){
				var confirmPass=$(".confirmPass").val();
				var pass=$(".password").val();
				if (confirmPass!==pass){
					Vue.prototype.$message({
						message:'密码不一致！',
						type: 'warning'
					});
				}
			},
			//注册验证
			registered(){
				var that=this;
				var confirmPass=$(".confirmPass").val();
				var email=$(".email").val();
				var emailPatt = /^[a-z\d]+(\.[a-z\d]+)*@([\da-z](-[\da-z])?)+(\.{1,2}[a-z]+)+$/;
				var passwordPatt = /^\w{5,12}$/;
				var pass=$(".password").val();
				var verificationCode=$(".verification-code").val();
				if (!emailPatt.test(email) || !passwordPatt.test(pass)
								|| confirmPass!==pass || confirmPass==="" ||email===""&& pass===""){
					Vue.prototype.$message.error('请检查输入的信息是否正确');
					return false;
				}else {
					$.post(
							"/competitions/regist.do",
							{sessionCode:verificationCode,uname:email,upass:pass},
							function (data) {
							var  Content=data.responseContent;
							if (data.responseCode===200){
								Vue.prototype.$confirm('注册成功，去登录?', '提示', {
									confirmButtonText: '确定',
									cancelButtonText: '取消',
									type: 'success'
								}).then(() => {
									/*Vue.prototype.$message({
										type: 'success',
										message: '登录!'
									});*/
									location.href="log.html"
								}).catch(() => {
									Vue.prototype.$message({
										type: 'info',
										message: '已取消'
									});
								});
							/*	Vue.prototype.$message({
									message:Content,
									type: 'success'
								});*/

								}else {
									Vue.prototype.$message.error(Content);
							}
					},"json"
					)
				}
			}
		},
		mounted:function () {
			var that = this;
		}

	})
</script>
</body>
</html>
